<script type="text/javascript">
$(document).ready(function(){
	$("#add").on("click",function(){
		window.location.href="${path}/company/addHtml";
	});
	$("button[data-type='editor-button']").on("click",function(e){
		var id = $(this).attr("data-id");
		window.location.href='${path}/company/editorHtml?companyId='+ id;
	});
	$("button[data-type='delect-button']").on("click",function(e){
		var id = $(this).attr("data-id");
		$.post("${path}/company/delect",{companyId:id},function(data){
			if(data.success){
				location.reload();
			}
		});
	});
	
	$("#delects").on("click",function(){
		var company = "";
		var checkbox=$("input[name='check']");
	    for(i=0;i<checkbox.length;i++){
	        if(checkbox[i].checked){
	        	company = company + checkbox[i].value + ",";
	        }
	    }
	    if(company == ""){
	    	alert("什么都没选中");
	    } else {
	    	$.post("${path}/company/delects",{companyIds:company},function(data){
	    		if(data.success){
	    			location.reload();
	    		}
	    	});
	    }
	});
	
	var allpro = document.getElementsByName("check");//复选框集合
	var all = document.getElementById("all");//全选按钮
	//全选
	$("input[name='all']").on("click",function(){
		 //全选按钮被选中时，遍历所有按钮
	     if (all.checked) {
	    	 for (var i = 0; i < allpro.length; i++) {
	     		if (allpro[i].type=="checkbox") {
	     			allpro[i].checked=true;
	     		}
	     	 }
	     //全选按钮未被选中时
	     }else{
	     	for (var i = 0; i < allpro.length; i++) {
	     		if (allpro[i].type=="checkbox") {
	     			allpro[i].checked=false;
	     		}
	     	}
	     }
	});
	//点击复选框，检验是否全部选中
	$("input[data-type='click-input']").on("click",function(e){
		var flag = true;
		for (var i = 0; i < allpro.length; i++) {
			if (allpro[i].type=="checkbox" && allpro[i].checked==false) {
     			all.checked = false;
     			flag = false;
     			break;
     		}
			if(flag){
				all.checked = true;
			}
		}
	});
});
</script>
<div>
	<form action="${path}/company/list" method="post">
		<input name="params">
		<button>查询</button>
	</form>
	<button id="add">添加</button><button id="delects">删除</button>
	<br/>
	<table border="1">
		<tr>
			<td>全选<input type="checkbox" name="all" id="all"/></td>
			<td>序号</td>
			<td>单位名称</td>
			<td>单位简介</td>
			<td>单位代码</td>
			<td>单位级别</td>
			<td>上级单位</td>
			<td>单位地址</td>
			<td>单位负责人</td>
			<td>操作</td>
		</tr>
		#foreach ($item in $list)
		<tr>
				<td><input data-type='click-input' type="checkbox" name="check" value="${item.id}" /></td>
				<td>$!{velocityCount}: </td>
				<td>${item.name}</td>
				<td>#if($item.introduction) ${item.introduction} #else 无  #end</td>
				<td>#if($item.code) ${item.code}  #else 无  #end</td>
				<td>#if($item.grade) ${item.grade} #else 无  #end</td>
				<td>#if($item.parent_unit) ${item.parent_unit} #else 无  #end</td>
				<td>#if($item.address) ${item.address}  #else 无  #end</td>
				<td>#if($item.liable_peoper) ${item.liable_peoper} #else 无  #end</td>
				<td><button type='button' data-type='editor-button'  data-id="${item.id}">修改</button>
				<button type='button' data-type='delect-button'  data-id="${item.id}">删除</button></td>
		</tr>
		#end
	</table>
</div>